Skip to content

fix(ir): 캡션/각주/미주 평문화에서 ListItemBlock 누락 정정#7

Merged
DanMeon merged 1 commit into
mainfrom
fix/listitem-in-furniture-plain-text
Apr 28, 2026
Merged

fix(ir): 캡션/각주/미주 평문화에서 ListItemBlock 누락 정정#7
DanMeon merged 1 commit into
mainfrom
fix/listitem-in-furniture-plain-text

Conversation

@DanMeon
Copy link
Copy Markdown
Owner

@DanMeon DanMeon commented Apr 28, 2026

Summary

`HwpLoader(mode="ir-blocks")` 와 CLI `rhwp-py blocks --format text` 가 각주·미주·캡션 본문을 평문화할 때 `ParagraphBlock` 만 처리하여, 본문 안의 `ListItemBlock` 이 통째로 RAG 색인에서 누락됐다.

  • `python/rhwp/ir/_plain_text.py` 신규 — `block_inline_text` / `join_inline_blocks` 헬퍼. `ParagraphBlock` + `ListItemBlock` + `FormulaBlock` + `FieldBlock` 을 인라인-스러운 블록으로 분류해 평문 추출하는 SSOT.
  • `langchain.py` 의 `_caption_plain_text` 제거, footnote/endnote/caption/picture 분기에서 헬퍼 사용.
  • `cli/ir.py` 의 `_caption_plain` 제거, `_block_to_text` 가 같은 헬퍼 사용 (DRY).
  • 헬퍼 단위 테스트 + LangChain·CLI 회귀 테스트 추가.

Why

ParaShape.head_type 가 비-None 이면 `_flatten_paragraph` 가 `ParagraphBlock` 대신 `ListItemBlock` 을 emit 한다. 각주 본문에 list 가 있는 HWP 문서는:

  1. LangChain Document 의 `page_content` 가 비거나 list 항목이 빠진다 (빈 `page_content` 는 loader 상위에서 strip 후 skip → 각주 통째로 RAG 검색에서 사라짐)
  2. CLI `--format text` 도 동일 누락

`spec § 5` 의 "캡션 안의 인라인 수식·필드도 자연스럽게 표현" 정책이 `_caption_plain_text` 에는 적용됐지만 footnote/endnote 평문화에는 누락된 채로 ParagraphBlock-only 였음 — 두 헬퍼 정책 일관성 깨짐도 동시 정정.

Related Issues

없음 — 코드 리뷰 중 발견.

Test plan

  • `uv run pytest tests/ -m "not slow"` → 450 passed, 2 skipped (sample 한정)
  • `uv run pyright python/ tests/` → 4 intentional errors only (`tests/type_check_errors.py` SSOT 보존)
  • 신규 단위 테스트: `test_ir_plain_text.py` (헬퍼 정확성)
  • 회귀 테스트: footnote with list_items / caption with formula+field 모두 평문에 포함됨
  • CI green

LangChain HwpLoader (mode=ir-blocks) 와 CLI rhwp-py blocks --format text 가
각주·미주·캡션 본문을 평문화할 때 ParagraphBlock 만 처리하여, 본문 안의
ListItemBlock 이 통째로 RAG 색인에서 누락됐다.

변환 경로상 ParaShape.head_type 가 비-None 이면 _flatten_paragraph 가
ParagraphBlock 대신 ListItemBlock 을 emit 하므로, 각주 본문에 list 가 있는
HWP 문서는 LangChain Document 의 page_content 가 비거나 list 항목이
빠진다. CLI text 포맷도 같은 누락.

수정:
- python/rhwp/ir/_plain_text.py 신규 — block_inline_text / join_inline_blocks
  헬퍼. ParagraphBlock + ListItemBlock + FormulaBlock + FieldBlock 을 인라인-
  스러운 블록으로 분류해 평문 추출. LangChain integration 과 CLI 가 공유
  하는 SSOT.
- langchain.py 의 _caption_plain_text 제거, footnote/endnote/caption/picture
  분기에서 join_inline_blocks 사용.
- cli/ir.py 의 _caption_plain 제거, _block_to_text 의 footnote/endnote/caption
  분기에서 같은 헬퍼 사용. PictureBlock caption 분기도 동일.

테스트:
- tests/test_ir_plain_text.py 신규 — 헬퍼 단위 테스트 (인라인/구조/빈
  블록 분류 + ListItemBlock 결합).
- tests/test_langchain_loader_ir.py 에 footnote/caption 회귀 테스트 2종 추가
  (private helper 직접 호출 — sample 파일의 footnote 구조에 의존하지 않음).
- tests/test_cli.py 에 _block_to_text footnote 회귀 테스트 1종 추가.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@DanMeon DanMeon merged commit 1709b87 into main Apr 28, 2026
13 checks passed
@DanMeon DanMeon deleted the fix/listitem-in-furniture-plain-text branch April 28, 2026 08:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant